<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: mtxDigitalIOExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('mtxDigitalIOExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">mtxDigitalIOExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Sets patterns on digital outputs and acts on digital inputs. Attach LEDs to the outputs and buttons to the digital inputs to use. (See the Pioneer LX manual and robots.mobilerobots.com for more details.) The 'mtx' Linux kernel module must be loaded, and the /dev/mtx character device must have been created (see mtxIODriver documentation). You must have read/write access to /dev/mtx.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArMTXIO.h&quot;</span></div><div class="line"><span class="preprocessor">#include &lt;stdint.h&gt;</span></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> printBits(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> byte) </div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> bit; </div><div class="line">  <span class="keywordtype">int</span> ch;</div><div class="line">  <span class="keywordflow">for</span>(bit = 7, ch = 0; bit &gt;= 0; bit--,ch++)</div><div class="line">  {</div><div class="line">    <span class="keywordflow">if</span>(ch == 4)</div><div class="line">       printf(<span class="stringliteral">&quot; &quot;</span>);</div><div class="line">    <span class="keywordflow">if</span> ((byte&gt;&gt;bit)&amp;1)</div><div class="line">       printf(<span class="stringliteral">&quot;1&quot;</span>);</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">       printf(<span class="stringliteral">&quot;0&quot;</span>);</div><div class="line">  }</div><div class="line">  <span class="comment">//printf(&quot; (0x%04x) &quot;, byte);</span></div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">  <a name="a0"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a name="_a1"></a><a class="code" href="classArArgumentParser.html">ArArgumentParser</a> parser(&amp;argc, argv);</div><div class="line">  parser.<a name="a2"></a><a class="code" href="classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (!<a name="a3"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>() || !parser.<a name="a4"></a><a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">  {</div><div class="line">    <a name="a5"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a name="a6"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">  }</div><div class="line"></div><div class="line">  <a name="_a7"></a><a class="code" href="classArMTXIO.html">ArMTXIO</a> mtxIO;</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span>(!mtxIO.<a name="a8"></a><a class="code" href="classArMTXIO.html#a77e058904a383074449322d3dcb2e6a3">isEnabled</a>())</div><div class="line">  {</div><div class="line">    <a name="a9"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a10"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;mtxIO: Error opening MTX IO device interface!&quot;</span>);</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(4);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> out = 1;</div><div class="line">  <span class="keywordflow">while</span>(<span class="keyword">true</span>)</div><div class="line">  {</div><div class="line">    mtxIO.<a name="a11"></a><a class="code" href="classArMTXIO.html#a2860f600f2d9d64540e8371b32928311">lock</a>();</div><div class="line"></div><div class="line">    <span class="comment">// print state of inputs</span></div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> inp;</div><div class="line">    mtxIO.<a name="a12"></a><a class="code" href="classArMTXIO.html#ac47bff0a034ae88b148c47b2efe88812">getDigitalIOInputMon1</a>(&amp;inp);</div><div class="line">    printf(<span class="stringliteral">&quot;Input 1: &quot;</span>);</div><div class="line">    printBits(inp);</div><div class="line">    printf(<span class="stringliteral">&quot; | &quot;</span>);</div><div class="line">    mtxIO.<a name="a13"></a><a class="code" href="classArMTXIO.html#a2521d19b43ce084c8a94e06bad46e7d2">getDigitalIOInputMon2</a>(&amp;inp);</div><div class="line">    printf(<span class="stringliteral">&quot;Input 2: &quot;</span>);</div><div class="line">    printBits(inp);</div><div class="line">    printf(<span class="stringliteral">&quot; | &quot;</span>);</div><div class="line"></div><div class="line">    </div><div class="line"></div><div class="line"><span class="comment">/* shouldn&#39;t be neccesary</span></div><div class="line"><span class="comment">    unsigned char cur;</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">    // get current state</span></div><div class="line"><span class="comment">    if(!mtxIO.getDigitalOutputControl1(&amp;cur))</span></div><div class="line"><span class="comment">    {</span></div><div class="line"><span class="comment">      ArLog::log(ArLog::Terse, &quot;mtxIO: Error getting current state of output control 1&quot;);</span></div><div class="line"><span class="comment">      mtxIO.unlock();</span></div><div class="line"><span class="comment">      Aria::exit(2);</span></div><div class="line"><span class="comment">    }</span></div><div class="line"><span class="comment">*/</span></div><div class="line"></div><div class="line">    <span class="comment">// set new state on both output banks</span></div><div class="line"></div><div class="line">    printf(<span class="stringliteral">&quot;Output 1: &quot;</span>);</div><div class="line">    printBits(out);</div><div class="line">    printf(<span class="stringliteral">&quot; | &quot;</span>);</div><div class="line">    <span class="keywordflow">if</span>(!mtxIO.<a name="a14"></a>setDigitalOutputControl1(&amp;out))</div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;mtxIO: Error setting state of output control 1&quot;</span>);</div><div class="line">      mtxIO.<a name="a15"></a><a class="code" href="classArMTXIO.html#a30f799f1e10d8120ce2461cb49505941">unlock</a>();</div><div class="line">      <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(3);</div><div class="line">    }</div><div class="line"></div><div class="line">    printf(<span class="stringliteral">&quot;Output 2: &quot;</span>);</div><div class="line">    printBits(out);</div><div class="line">    printf(<span class="stringliteral">&quot; | &quot;</span>);</div><div class="line">    <span class="keywordflow">if</span>(!mtxIO.<a name="a16"></a>setDigitalOutputControl2(&amp;out))</div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;mtxIO: Error setting state of output control 2&quot;</span>);</div><div class="line">      mtxIO.<a class="code" href="classArMTXIO.html#a30f799f1e10d8120ce2461cb49505941">unlock</a>();</div><div class="line">      <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(3);</div><div class="line">    }</div><div class="line">  </div><div class="line">    <span class="comment">// wait</span></div><div class="line">    mtxIO.<a class="code" href="classArMTXIO.html#a30f799f1e10d8120ce2461cb49505941">unlock</a>();</div><div class="line">    <a name="a17"></a><a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(500);</div><div class="line"> </div><div class="line">    <span class="comment">// shift </span></div><div class="line">    </div><div class="line">    out = out &lt;&lt; 1;</div><div class="line">    <span class="keywordflow">if</span>(out == 0) out = 1;</div><div class="line"></div><div class="line">    puts(<span class="stringliteral">&quot;&quot;</span>);</div><div class="line">  }</div><div class="line">    </div><div class="line">    </div><div class="line">    </div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line"></div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
